import { Bus, CHART_KLINE__ITEM, CHART_KLINE__LIST, CONN_ACTIVITY, CONN_RANK } from "./Bus";
import { IBroadcast } from "./IBroadcast";

export class RankBroadcast extends IBroadcast {
    channelParam: any[] = [
        // { event: "subscribe", group: "all", topic: "COINS" },
        // { event: "subscribe", group: "NEW", topic: "COINS" },
        { event: "subscribe", group: "ALL", topic: "COINS" },
        // { event: "subscribe", group: "HOT", topic: "COINS" },
        // { event: "subscribe", group: "UP", topic: "COINS" },
        // { event: "subscribe", group: "DOWN", topic: "COINS" },
        // { event: "subscribe", group: "TURNOVER", topic: "COINS" },
        // { event: "subscribe", group: "VOLATILITY", topic: "COINS" },
        // { event: "subscribe", group: "CAPITAL_ABNORMAL", topic: "COINS" },
        { event: "subscribe", group: "REAL_TIME_BIG_TURNOVER", topic: "COINS" }
    ];

    subParam: any[] = [
        // { event: "subscribe", group: "ALL", topic: "COINS" },
        // { event: "subscribe", group: "HOT", topic: "COINS" },
        // { event: "subscribe", group: "UP", topic: "COINS" },
        // { event: "subscribe", group: "DOWN", topic: "COINS" },
        // { event: "subscribe", group: "TURNOVER", topic: "COINS" },
        // { event: "subscribe", group: "VOLATILITY", topic: "COINS" },
        // { event: "subscribe", group: "REAL_TIME_BIG_TURNOVER", topic: "COINS" }
    ];

    subscribe(): void {
        // console.log("訂閱榜單");
        this.unSubscribe();
        this.channelParam.forEach(i => {
            // this.channelStr = JSON.stringify(i);
            this.send(JSON.stringify(i));
        });
    }

    unSubscribe(): void {
        this.channelParam.forEach(i => {
            // this.channelStr = JSON.stringify(i);
            const obj = { ...i };
            obj.event = "unsubscribe";
            this.send(JSON.stringify(obj));
        });
    }

    handle(jsondata: any): void {
        // console.log("rank", jsondata);
        Bus.emit(CONN_RANK, jsondata);
    }
}
